package cn.sylinx.common.lang;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 处理日期格式化或者数值格式化工具类
 * 
 * @author sylinx 2012-8-12 下午02:28:12
 */
public class FormaterParseUtil {

    private static FormaterParseUtil instance = new FormaterParseUtil();

    public static FormaterParseUtil getInstatnce() {
        return instance;
    }

    public static Date parseDate(String dateStr, String timeFormate) {
        SimpleDateFormat timeFormater = new SimpleDateFormat(timeFormate);
        try {
            if (StringUtil.isNotBlank(dateStr)) {
                return timeFormater.parse(dateStr);
            }
        } catch (Exception e) {
        }
        return null;
    }

    public static Date parseEnDate(String dateStr, String timeFormate) {
        SimpleDateFormat timeFormater = new SimpleDateFormat(timeFormate, Locale.ENGLISH);
        try {
            if (StringUtil.isNotBlank(dateStr)) {
                return timeFormater.parse(dateStr);
            }
        } catch (Exception e) {
        }
        return null;
    }
    
    public static String dateToString(Date date) {
        SimpleDateFormat timeFormater = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (null != date) {
                return timeFormater.format(date);
            }
        } catch (Exception e) {
        }
        return "";
    }
    
    public static String dateToString(Date date, String timeFormate) {
        SimpleDateFormat timeFormater = new SimpleDateFormat(timeFormate);
        try {
            if (null != date) {
                return timeFormater.format(date);
            }
        } catch (Exception e) {
        }
        return "";
    }

    public static Date parseDate(SimpleDateFormat timeFormater, String dateStr) {
        try {
            if (StringUtil.isNotBlank(dateStr)) {
                return timeFormater.parse(dateStr);
            }
        } catch (Exception e) {
        }
        return null;
    }
  
}
